<template>
  <div class="zhgd-construct-situation-container">
    <div v-loading="loading"
         v-if="loading"
         element-loading-text="拼命加载中"
         element-loading-spinner="el-icon-loading"
         element-loading-background="rgba(0, 0, 0, 0.8)"
         class="loading-style"></div>
    <el-form ref="requestParams"
             :model="requestParams"
             label-width="100px">
      <el-col :span="6">
        <el-form-item label="项目编号">
          <el-input v-model="requestParams.project_id"
                    placeholder="请输入项目编号"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="项目名称">
          <el-input v-model="requestParams.project_name"
                    placeholder="请输入项目名称"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="所属分公司">
          <el-select v-model="requestParams.org_name"
                     class="common-style"
                     clearable
                     filterable
                     placeholder="请选择">
            <el-option label="全部"
                       value=""></el-option>
            <el-option v-for="item in belogCompArr"
                       :key="item"
                       :label="item"
                       :value="item">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="所属子公司"
                      width="130">
          <el-select v-model="requestParams.sub_org_name"
                     class="common-style"
                     clearable
                     filterable
                     placeholder="请选择">
            <el-option label="全部"
                       value=""></el-option>
            <el-option v-for="item in belogSubCompArr"
                       :key="item"
                       :label="item"
                       :value="item">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="接入情况">
          <el-select v-model="requestParams.butt_situation"
                     class="common-style"
                     clearable
                     placeholder="请选择">
            <!-- <el-option label="全部"
                       value=""></el-option> -->
            <el-option v-for="item in buttSituationArr"
                       :key="item.value"
                       :label="item.name"
                       :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="进度部位">
          <el-select v-model="projectStageArr"
                     class="common-style"
                     clearable
                     multiple
                     collapse-tags
                     placeholder="请选择">
            <!-- <el-option label="全部"
                       value=""></el-option> -->
            <el-option v-for="item in ProjecPhaseArr"
                       :key="item.value"
                       :label="item.name"
                       :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="承包类型">
          <el-select v-model="requestParams.contract_type"
                     class="common-style"
                     clearable
                     placeholder="请选择">
            <!-- <el-option label="全部"
                       value=""></el-option> -->
            <el-option v-for="item in contractTypeArr"
                       :key="item.value"
                       :label="item.name"
                       :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="是否大屏界面"
                      width="140">
          <el-select v-model="requestParams.is_has_screen"
                     class="common-style"
                     clearable
                     placeholder="请选择">
            <!-- <el-option label="全部"
                       value=""></el-option> -->
            <el-option v-for="item in ynArr"
                       :key="item.value"
                       :label="item.name"
                       :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="是否参与统计"
                      width="130">
          <el-select v-model="requestParams.is_join_statistics"
                     class="common-style"
                     clearable
                     placeholder="请选择">
            <!-- <el-option label="全部"
                       value=""></el-option> -->
            <el-option v-for="item in ynArr"
                       :key="item.value"
                       :label="item.name"
                       :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="未接入原因">
          <el-select v-model="requestParams.not_butt_reason"
                     class="common-style"
                     clearable
                     placeholder="请选择">
            <!-- <el-option label="全部"
                       value=""></el-option> -->
            <el-option v-for="item in notButtReasonArr"
                       :key="item.value"
                       :label="item.name"
                       :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="9">
        <el-form-item label="项目地址">
          <LocationSelect :locaData.sync="requestParams"></LocationSelect>
          <!-- <el-cascader placeholder="请选择收货地址"
                       @change="locationCascader"
                       clearable
                       :props="cascaderProps"
                       v-model="requestParams.address"
                       class="choose-location-cascader"
                       :options="addressOptions">
          </el-cascader> -->
        </el-form-item>
      </el-col>
      <el-col :span="3"
              class="condition-right-button">
        <el-button type="primary"
                   @click="onSearch">查询</el-button>
        <el-button @click="onReset"
                   style="color:black!important;">重置</el-button>
      </el-col>
      <el-col :span="24"
              class="button-opera-style">
        <el-button :type="judgeDataIsNull() ? 'info' : 'primary'"
                   v-auth="'zhgd-construct-export-all'"
                   :disabled="judgeDataIsNull() ? true : false"
                   @click="onAllExport">全部导出</el-button>
        <!-- <el-button :type="dataIsEmpty()?'primary':'info'"
                   :disabled="dataIsEmpty()?false:true"
                   @click="onScreenDataMaitain">大屏数据维护</el-button>
                   统计报表导出（ps:现在不整）
                   <el-button :type="dataIsEmpty()?'primary':'info'"
                   :disabled="dataIsEmpty()?false:true">统计报表导出</el-button>
        -->

        <!--  -->

        <!-- v-if="isShowExportCountReport()" -->
        <el-button type="primary"
                   v-auth="'export-count-report'"
                   @click="onExportCountReport">统计报表导出</el-button>
      </el-col>
      <el-col :span="24">
        <el-table :data="tableData"
                  ref="filterTable"
                  :highlight-current-row="true"
                  border
                  :row-key="getRowKey"
                  @sort-change="onSortChange"
                  @selection-change="onSelectChange"
                  height="500"
                  :header-cell-style="{ background: '#f5f5f5' }">
          <!-- <el-table-column type="selection"
                           fixed
                           :reserve-selection="true">
          </el-table-column> -->
          <el-table-column type="index"
                           fixed
                           label="序号"
                           sortable
                           width="60"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <!--          <el-table-column prop="project_id"-->
          <!--                           fixed-->
          <!--                           label="项目编号"-->
          <!--                           sortable-->
          <!--                           width="120"-->
          <!--                           align="center"-->
          <!--                           show-overflow-tooltip>-->
          <!--          </el-table-column>-->
          <el-table-column prop="project_name"
                           label="项目名称"
                           fixed
                           width="300"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="项目接入情况"
                           fixed
                           width="200"
                           align="center">
            <template slot-scope="scope">
              <div class="img-box">
                <img v-for="(item, ind) in projectSituationImg"
                     :key="ind"
                     :src="getCurrentImg(item, ind, scope.row)"
                     class="img-size" />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="项目地址"
                           align="center"
                           width="200"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.province+'/'+scope.row.city+'/'+scope.row.area}}</span>
            </template>
          </el-table-column>
          <el-table-column label="进度部位"
                           align="center"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ getValueName(scope.row.project_stage, "xmjd") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="承包类型"
                           align="center"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ getValueName(scope.row.contract_type, "cblx") }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="sub_org_name"
                           label="所属子公司"
                           align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="org_name"
                           label="所属分公司"
                           width="140"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="project_time"
                           label="立项时间"
                           align="center"
                           width="120"
                           sortable
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="是否参与统计"
                           align="center"
                           v-auth="'is-part-count'"
                           width="160"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tooltip class="item"
                          effect="dark"
                          content="双击切换"
                          placement="top">
                <span class="account-style"
                      @dblclick="onSwitchChange(scope.row)">
                  {{ scope.row.is_join_statistics == 1 ? "是" : "否" }}
                </span>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column prop="is_has_screen"
                           label="是否有大屏界面"
                           width="160"
                           align="center"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.is_has_screen == 1 ? "是" : "否" }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="未接入原因"
                           width="150"
                           align="center"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{
                getValueName(scope.row.not_butt_reason, "wjryy")
              }}</span>
            </template>
          </el-table-column> -->
          <el-table-column label="接入情况"
                           align="center"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ getValueName(scope.row.butt_situation, "jrqk") }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="is_butt_labor"
                           label="是否对接劳务实名"
                           width="180"
                           align="center"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.is_butt_labor == 1 ? "是" : "否" }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="labor_supplier"
                           label="劳务实名制供应商"
                           width="180"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="labor_butt_time"
                           label="劳务实名制接入时间"
                           width="180"
                           align="center"
                           sortable
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="labor_not_butt_reason"
                           label="劳务实名制未对接原因"
                           width="180"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="是否对接扬尘监控"
                           width="180"
                           align="center"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.is_butt_dust == 1 ? "是" : "否" }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="dust_supplier"
                           label="扬尘监控供应商"
                           width="180"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="dust_butt_time"
                           label="扬尘监控接入时间"
                           width="180"
                           sortable
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="dust_not_butt_reason"
                           label="扬尘监控未对接原因"
                           width="180"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="是否对接塔机黑匣子"
                           width="160"
                           align="center"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.is_butt_tower == 1 ? "是" : "否" }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="tower_supplier"
                           label="塔机黑匣子供应商"
                           width="160"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="tower_butt_time"
                           label="塔机黑匣子接入时间"
                           width="180"
                           align="center"
                           sortable
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="tower_not_butt_reason"
                           label="塔机黑匣子未对接原因"
                           width="180"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="是否对接视频监控"
                           width="160"
                           align="center"
                           show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.is_butt_video == 1 ? "是" : "否" }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="video_supplier"
                           label="视频监控供应商"
                           width="140"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="video_butt_time"
                           label="视频监控接入时间"
                           width="160"
                           sortable
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="video_not_butt_reason"
                           label="视频监控未对接原因"
                           width="160"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="操作"
                           align="center"
                           width="120"
                           fixed="right">
            <template slot-scope="scope">
              <el-button type="text"
                         @click="onScreenDataMaintain(scope.row)">大屏数据维护</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
      <el-col :span="24"
              class="bottom-box">
        <el-pagination @current-change="handlePageChange"
                       @size-change="handleSizeChange"
                       :page-sizes="[100, 200, 300]"
                       :current-page="requestParams.page"
                       :page-size="requestParams.page_size"
                       layout="total,sizes,prev, pager, next, jumper"
                       :total="total"
                       align="center">
        </el-pagination>
      </el-col>
    </el-form>
  </div>
</template>

<script>
import LocationSelect from "@/components/LocationSelect/LocationSelect";
import { standardCodeApi } from "@/services/StandardCode";
import { ZHGDConsSitApi } from "@/services/ProjectCenter";
export default {
  components: {
    LocationSelect,// 省、市、区
  },
  data () {
    return {
      cascaderProps: {//参数
        checkStrictly: true,//父子节点不互相关联
        emitPath: false,
        value: 'value',
        children: 'children',
        label: 'label'
      },
      // 省市区数据
      addressOptions: [],
      projectSituationImg: [
        {
          yes: require("@/assets/projectInterSituationIcon/lwhz-yes.png"),
          no: require("@/assets/projectInterSituationIcon/lwhz-no.png")
        },
        {
          yes: require("@/assets/projectInterSituationIcon/ycjc-yes.png"),
          no: require("@/assets/projectInterSituationIcon/ycjc-no.png")
        },
        {
          yes: require("@/assets/projectInterSituationIcon/tjhxz-yes.png"),
          no: require("@/assets/projectInterSituationIcon/tjhxz-no.png")
        },
        {
          yes: require("@/assets/projectInterSituationIcon/spjk-yes.png"),
          no: require("@/assets/projectInterSituationIcon/spjk-no.png")
        }
      ],
      img: "../../../assets/ali.png",
      belogCompArr: [],
      belogSubCompArr: [],
      isShow: false,
      notButtReasonArr: [], //接入原因
      selectionArr: [], //选中的数组
      selIdsArr: [], //选中的主键值
      loading: true, //加载
      showClose: false,
      messageContent: `<p style="width:200px;">正在准备数据，请等待</p>`,
      percentage: 0, //下载进度条
      projectStageArr: [], //进度部位
      ynArr: [
        { name: "是", value: 1 },
        { name: "否", value: 0 }
      ],
      buttSituationArr: [], //对接情况
      ProjecPhaseArr: [], //进度部位
      contractTypeArr: [], //承包类型
      todosPdf: "",
      dialogVisible: false, //pdf格式的文件弹框
      lookImgDialog: false,
      imgUrl: "", //图片的链接
      objRow: {},
      deepDesignConfimDialog: false,
      proIdArr: [], //主键值数组
      tableData: [],
      timeArr: null,
      statusArr: [
        { name: "已确认", value: 1 },
        { name: "未确认", value: 0 }
      ],
      total: 0,
      requestParams: {
        company_id: "", //单位主键值
        is_page: 1, //是否分页
        page: 1,
        page_size: 100, //每页显示的最大条数
        project_id: "",
        project_name: "",
        sub_org_name: "",
        org_name: "",
        butt_situation: "",
        project_stage: "",
        contract_type: "",
        is_has_screen: "",
        is_join_statistics: 1,
        order: "", //升序:asc;   降序:desc
        order_field: "",
        not_butt_reason: "",
        province_no: "",//省
        city_no: "",//市
        area_no: "",//区
      }
    };
  },
  methods: {
    // 选择省市区
    locationCascader (item) {
      console.log(item, 'change')
      if (item.length === 3) {
        this.onSearch();//查询
      }
    },
    // 地址数据
    getAddressData () {
      fetch(`/static/area.json`, {
        method: 'get',
        headers: {
          'Content-Type': 'application/json'
        }
      }).then(res => {
        return res.json()
      }).then(res => {
        this.addressOptions = res.data
        console.log(this.addressOptions, 'address options')
      })
    },
    getCurrentImg (item, ind, currentObj) {
      if (ind == 0) {
        //是否对接劳务实名
        if (currentObj.is_butt_labor === 1) {
          return item.yes;
        } else {
          return item.no;
        }
      } else if (ind == 1) {
        //是否对接扬尘监控
        if (currentObj.is_butt_dust === 1) {
          return item.yes;
        } else {
          return item.no;
        }
      } else if (ind == 2) {
        //是否对接考勤机黑匣子
        if (currentObj.is_butt_tower === 1) {
          return item.yes;
        } else {
          return item.no;
        }
      } else if (ind == 3) {
        //是否对接视频监控
        if (currentObj.is_butt_video === 1) {
          return item.yes;
        } else {
          return item.no;
        }
      } else {
        return "";
      }
    },
    getExistButtonAuth (arr) {
      //递归
      arr.map(ele => {
        if (ele.object_no == "export-count-report") {
          this.isShow = true;
        } else {
          if (ele.children_list && ele.children_list.length > 0) {
            this.getExistButtonAuth(ele.children_list);
          }
        }
      });
    },
    async isShowExportCountReport () {
      //统计报表导出是否显示
      this.isShow = false; //重置
      let industryUserAuth =
        window.localStorage.getItem("industryUserAuth") || "[]";
      let arr = JSON.parse(industryUserAuth);
      await this.getExistButtonAuth(arr); //权限按钮是否存在
      return this.isShow;
    },
    onExportCountReport () {
      //统计报表导出
      // this.$message.warning('开发中');
      this.loading = true;
      // let obj = Object.assign({}, this.requestParams)
      // this.$delete(obj, 'is_page');
      // this.$delete(obj, 'page');
      // this.$delete(obj, 'page_size');
      ZHGDConsSitApi.exportCountReport({
        // params: { ...obj },
        params: {},
        onDownloadProgress: progressEvent => {
          //下载进度
          this.percentage =
            ((progressEvent.loaded / progressEvent.total) * 100) | 0;
        }
      }).then(res => {
        let a = document.createElement("a");
        let blob = new Blob([res], { type: "application/vnd.ms-excel" });
        a.href = URL.createObjectURL(blob);
        a.download = "智慧工地对接项目表";
        a.target = "_blank";
        a.click();
        this.getNotify();
        this.loading = false;
      });
    },
    onSwitchChange (row) {
      //是否参与统计
      this.loading = true;
      ZHGDConsSitApi.buttEditJoin({
        data: {
          project_id: row.project_id,
          is_join_statistics: row.is_join_statistics == 1 ? 0 : 1
        }
      })
        .then(res => {
          if (res.code == 0) {
            // this.$message.success('操作成功');
            this.getButtList(); //刷新
          }
        })
        .catch(error => {
          console.log(errror);
        });
    },
    getName (value, typeVal) {
      //获取进度部位的名称
      let valueName = "";
      let arr =
        typeVal == "xmjd"
          ? this.ProjecPhaseArr
          : typeVal == "cblx"
            ? this.contractTypeArr
            : typeVal == "jrqk"
              ? this.buttSituationArr
              : [];
      if (arr.length > 0) {
        arr.forEach(ele => {
          if (ele.value == String(value)) {
            valueName = ele.name;
          }
        });
      }
      return valueName;
    },
    getWJRYY (value, typeVal) {
      //未接入原因名称
      let valueName = "";
      let values = value == "" ? [] : value.split(",");
      if (values.length > 0) {
        //类型转换
        values.map(ele => {
          ele = String(ele);
        });
      }
      let arr = typeVal == "wjryy" ? this.notButtReasonArr : [];
      if (arr.length > 0) {
        arr.forEach(ele => {
          if (values.includes(ele.value)) {
            valueName = valueName + ele.name + ";";
          }
        });
      }
      return valueName;
    },
    getValueName (value, typeVal) {
      let valueName = "";
      if (typeVal == "wjryy") {
        valueName = this.getWJRYY(value, typeVal); //未接入原因
      } else {
        valueName = this.getName(value, typeVal); //获取名称
      }
      return valueName;
    },
    onScreenDataMaintain (row) {
      //大屏数据维护
      this.loading = true;
      this.$store.dispatch("setZHGDConSiInfo", row);
      this.$router.push({
        path: "screenDataMaintain",
        query: { project_id: row.project_id, project_name: row.project_name, is_butt_labor: row.is_butt_labor, is_butt_dust: row.is_butt_dust, is_butt_tower: row.is_butt_tower, is_butt_video: row.is_butt_video }
      });
    },
    dataIsEmpty () {
      //数据是否为空
      let isEmpty = false;
      if (this.selIdsArr.length > 0) {
        isEmpty = true;
      }
      return isEmpty;
    },
    judgeDataIsNull () {
      //判断表格数据是否为空
      let dataIsNull = true;
      if (this.tableData.length > 0) {
        dataIsNull = false;
      }
      return dataIsNull;
    },
    // 获取标准码
    getStandardCode (code, codeData, codeMap, codeLocal) {
      return standardCodeApi
        .getStandardCodeData({
          data: {
            code_type: code
          }
        })
        .then(
          res => {
            if (res.code === 0 && res.data.list) {
              this[codeData] = res.data.list;
              this[codeMap] = [];
              this[codeData].map(item => {
                this[codeMap].push(item);
                // this[codeMap][item.value] = item
              });
              window.localStorage.setItem(
                codeLocal,
                JSON.stringify(res.data.list)
              );
            }
          },
          err => {
            console.log(err);
          }
        );
    },
    // 初始化标准码
    async initCode (code, codeData, codeMap, codeLocal) {
      let local = window.localStorage.getItem(codeLocal);

      if (local) {
        this[codeData] = JSON.parse(local);
        this[codeMap] = [];
        this[codeData].map(item => {
          this[codeMap].push(item);
          //this[codeMap]一开始undefined,找不到item.value,会报错
          // this[codeMap][item.value] = item
        });
      } else {
        await this.getStandardCode(code, codeData, codeMap, codeLocal);
      }
    },
    getRowKey (row) {
      //唯一主键值
      return row.id;
    },
    onSelectChange (selection) {
      //选中时触发的事件
      this.selectionArr = selection || [];
      this.selIdsArr = [];
      if (selection.length > 0) {
        selection.forEach(ele => {
          this.selIdsArr.push(ele.project_id); //项目id
        });
      }
    },
    getOrder (column) {
      //升序或降序
      return column.order == "descending" ? "desc" : "asc";
    },
    onSortChange (column) {
      //排序
      this.requestParams.order_field = column.order = null ? "" : column.prop; //排序字段
      this.requestParams.order = column.order = null
        ? ""
        : this.getOrder(column.order); //排序字段
      this.handlePageChange(1); //刷新
    },
    getNotify () {
      this.notify = this.$notify({
        title: "下载进度",
        offset: 130,
        dangerouslyUseHTMLString: true,
        duration: 0,
        message: this.messageContent,
        customClass: "notify-download",
        showClose: true
        // showClose: this.showClose,
      });
    },
    onAllExport () {
      //全部导出
      this.loading = true;
      let obj = Object.assign({}, this.requestParams);
      this.$delete(obj, "is_page");
      this.$delete(obj, "page");
      this.$delete(obj, "page_size");
      ZHGDConsSitApi.buttExport({
        params: { ...obj },
        onDownloadProgress: progressEvent => {
          //下载进度
          this.percentage =
            ((progressEvent.loaded / progressEvent.total) * 100) | 0;
        }
      }).then(res => {
        let a = document.createElement("a");
        let blob = new Blob([res], { type: "application/vnd.ms-excel" });
        a.href = URL.createObjectURL(blob);
        a.download = "供应商对接总表";
        a.target = "_blank";
        a.click();
        this.getNotify();
        this.loading = false;
      });
    },
    getSelFirstInfo () {
      //选中的第一个数据
      let obj = {};
      let firstProId = this.selIdsArr[0];
      this.selectionArr.forEach(ele => {
        if (ele.project_id == firstProId) {
          obj = ele;
        }
      });
      return obj;
    },
    // onScreenDataMaitain () {//大屏数据维护 selectionArr
    //   this.$store.dispatch('setZHGDConSiInfo', this.getSelFirstInfo())
    //   this.$router.push({ path: 'screenDataMaintain', query: { proIds: this.selIdsArr.join(',') } })
    // },
    onSearch () {
      //查询
      this.loading = true;
      this.handlePageChange(1); //刷新
    },
    onReset () {
      //重置
      this.loading = true;
      this.projectStageArr = []; //进度部位
      this.$refs.filterTable.clearSort(); //排序的状态清空
      this.timeArr = null;
      this.requestParams = this.$options.data().requestParams; //重置
      this.getCompanyId(); //获取单位id
      this.onSearch(); //刷新
    },
    handleSizeChange (size) {
      //当前显示的最大条数
      this.requestParams.page_size = size;
      this.handlePageChange(1);
    },
    // 分页
    handlePageChange (page) {
      this.loading = true;
      this.requestParams.page = page;
      this.getButtList(); //智慧工地项目对接情况列表
    },
    async noPageGetButtList () {
      //不分页的所有数据
      await this.getCompanyId();
      return ZHGDConsSitApi.getButtList({
        params: {
          company_id: this.requestParams.company_id,
          is_page: 0 //不分页
        }
      })
        .then(res => {
          if (res.data) {
            let list = res.data.list || [];
            if (list) {
              if (list.length > 0) {
                list.forEach(item => {
                  if (
                    this.belogCompArr.indexOf(item.org_name) == -1 &&
                    item.org_name != "" &&
                    item.org_name != null
                  ) {
                    this.belogCompArr.push(item.org_name);
                  }

                  if (
                    this.belogSubCompArr.indexOf(item.sub_org_name) == -1 &&
                    item.sub_org_name != "" &&
                    item.sub_org_name != null
                  ) {
                    this.belogSubCompArr.push(item.sub_org_name);
                  }
                });
              }
            }
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    getButtList () {
      //获取智慧工地项目对接情况列表
      this.requestParams.project_stage = this.projectStageArr.join(","); //进度部位
      return ZHGDConsSitApi.getButtList({
        params: this.requestParams
      })
        .then(res => {
          if (res.data) {
            this.loading = false; //加载取消
            this.tableData = res.data.list;
            this.total = res.data.total_count; //总条数
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    getCompanyId () {
      //获取单位主键值
      let userInfo = JSON.parse(window.localStorage.userInfo) || {};
      this.requestParams.company_id = userInfo.comp_id || "";
    },
    // 未接入原因标准码
    getCodeNoToken () {
      this.notButtReasonArr = []
      standardCodeApi.getCodeNoToken({
        data: {
          code_type: 'notButtReason',
          is_page: 0,
          system_no: "industry",
          no_token: "1"
        }
      }).then((res) => {
        if (res.code === 0) {
          let list = res.data.length > 0 ? res.data[0].sub_data : []
          this.notButtReasonArr = list
        }
      }).catch((error) => {
        console.log(error)
      })
    },
  },
  async created () {
    // 从url种获取project_stage
    this.projectStageArr = this.$route.query.project_stage
      ? this.$route.query.project_stage.split(",")
      : [];
    await this.getCodeNoToken();//未接入原因
    this.getCompanyId();
    // 对接情况 标准码
    await this.initCode(
      "buttSituation",
      "buttSituationArr",
      "buttSituationMap",
      "buttSituationMap"
    ); //接入情况
    await this.initCode(
      "projectStage",
      "ProjecPhaseArr",
      "ProjecPhaseMap",
      "ProjecPhaseMap"
    ); //进度部位
    await this.initCode(
      "contractType",
      "contractTypeArr",
      "contractTypeMap",
      "contractTypeMap"
    ); //承包类型

    await this.getAddressData()
    await this.noPageGetButtList(); //未分页
    await this.getButtList(); //获取智慧工地项目对接情况列表
  },
  watch: {
    percentage (n, o) {
      if (this.percentage === 100) {
        this.messageContent = `<p style="width:100px;">下载完成<span style="float:right">${this.percentage}%</span></p>`;
        this.showClose = true;
        setTimeout(() => {
          this.notify.close();
        }, 5000);
      } else if (this.percentage > 0) {
        this.messageContent = `<p style="width:100px;">正在下载<span style="float:right">${this.percentage}%</span></p>`;
      } else {
        this.showClose = true;
        this.messageContent = `<p style="width:200px;">正在准备数据，请等待</p>`;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.zhgd-construct-situation-container {
  padding: 20px;
  position: relative;
  .account-style {
    cursor: pointer;
    color: blue;
  }
  .loading-style {
    width: 100%;
    height: calc(100vh + 145px);
    position: absolute;
    top: -20px;
    left: 0px;
  }
  .button-opera-style {
    margin-bottom: 24px;
  }
  .common-style {
    width: 100% !important;
  }
  .condition-right-button {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
  }
  .bottom-box {
    margin: 0px 0px 20px 0px;
  }
}
/deep/ .el-table__fixed {
  // 左固定列
  height: auto !important;
  bottom: 12px; // 改为自动高度后，设置与父容器的底部距离，高度会动态改变，值可以设置比滚动条的高度稍微大一些,这个根据实际情况改
}
/deep/ .el-table__fixed-right {
  // 右固定列
  height: auto !important;
  bottom: 12px;
}
.img-box {
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.img-size {
  width: 24px;
  height: 24px;
  margin: 0px 7px;
}
.choose-location-cascader {
  width: 100%;
}
</style>
